package io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class ReadStringDemo {
    public static void main(String[] args) throws IOException {

        /**File file = new File("abc.txt");
         System.out.println(file.getName());//名字
         System.out.println(file.length());//文件大小
         System.out.println(file.canRead());//是否是文件
         System.out.println(file.canWrite());//是否可写
         System.out.println(file.isFile());//是否是文件
         System.out.println(file.isDirectory());//是否是目录
         System.out.println(file.exists());//是否存在

         System.out.println("文件名："+file.getName());
         System.out.println("文件大小"+file.length());
         System.out.println("是否可写"+file.canRead());
         System.out.println("是否可读"+file.canWrite());
         System.out.println("是否是文件"+file.isFile());
         System.out.println("是否是目录"+file.isDirectory());
         System.out.println("是否存在"+file.exists());

         System.out.println(file.getName());
         System.out.println(file.exists());//是否存在
         System.out.println(file.isFile());//是否是文件
         System.out.println(file.canRead());//是否可写
         System.out.println(file.length());//文件大小
         System.out.println(file.canWrite());//是否可读
         System.out.println(file.isDirectory());//是否是目录

         File file = new File("acc.txt");
         if(file.exists()){
         System.out.println("文件已存在");
         }else {
         file.createNewFile();
         System.out.println("文件已创建");
         }

         if(file.exists()){
         file.delete();
         }else {
         file.createNewFile();
         }

         if(file.exists()){
         file.delete();
         }else {
         file.createNewFile();
         }


         File dir = new File("a/b/c/d");
         if(dir.exists()){

         }else {
         dir.mkdir();//创建目录
         dir.mkdirs();//创建目录和父目录
         dir.mkdir();
         dir.mkdir();
         dir.mkdirs();
         dir.mkdirs();
         }

         File file=new File("acc.txt");

         if(file.exists()){
         file.delete();
         }else {
         file.createNewFile();
         }
         if(file.exists()){
         file.delete();
         }else {
         file.createNewFile();
         }

         if (file.exists()){
         file.delete();
         }else {
         file.createNewFile();
         }


         if(file.isDirectory()){
         file.delete();
         }else {
         file.mkdirs();
         }
         if(file.isDirectory()){
         file.delete();
         }else {
         file.mkdirs();
         }
         if(file.isDirectory()){
         file.delete();
         }else {
         file.mkdirs();

         FileOutputStream fos = new FileOutputStream("mak.con");
         fos.write(1);
         fos.write(2);
         fos.close();

         fos.write(2);
         fos.write(2);
         FileOutputStream fos2 = new FileOutputStream("aa.a");
         FileOutputStream fos3 = new FileOutputStream("aa.b");
         fos.close();

         FileInputStream fis = new FileInputStream("and.ss");
         int i = fis.read();//读取字节
         System.out.println(i);
         fis.close();
         int s=fis.read();//读取字节；
         System.out.println(s);
         fis.close();
         int a=fis.read();//读取字节;

         FileInputStream fis = new FileInputStream("aa.a");
         FileOutputStream fos = new FileOutputStream("bb.b");
         int d;

         while((d=fis.read())!=-1){
         fos.write(d);
         }
         FileInputStream fis2 = new FileInputStream("aa.a");
         FileOutputStream fos2 = new FileOutputStream("bb.b");
         while ( (d=fis2.read())!=-1) {
         fos2.write(d);
         }
         fis2.close();

         FileInputStream fis3 = new FileInputStream("aa.a");
         FileOutputStream fos3 = new FileOutputStream("bb.b");
         while((d=fis3.read())!=-1){
         fos3.write(d);
         }


         FileOutputStream fis = new FileOutputStream("aa.a");
         String a="aaavvv";
         byte[] b=a.getBytes(StandardCharsets.UTF_8);
         fis.write(b);

         FileOutputStream fos = new FileOutputStream("bb.b");
         String c="232356";
         byte[] d=c.getBytes(StandardCharsets.UTF_8);
         fos.write(d);
         fos.close();
         FileOutputStream fos2 = new FileOutputStream("cc.c");
         String d2= "klsakf;s";
         byte[] d3=d2.getBytes(StandardCharsets.UTF_8);
         fos2.write(d3);
         fos2.close();


         File file = new File("aaa.a");
         FileInputStream fis = new FileInputStream(file);
         byte[] bytes = new byte[(int)file.length()];
         fis.read(bytes);
         String s = new String(bytes, StandardCharsets.UTF_8);
         System.out.println(s);
         fis.close();
         File file = new File("aa.a");
         FileInputStream fis = new FileInputStream(file);
         byte[] bytes = new byte[(int)file.length()];
         fis.read(bytes);
         String s = new String(bytes , StandardCharsets.UTF_8);
         System.out.println(s);
         fis.close();

         File file = new File("aa.a");
         FileInputStream fis = new FileInputStream(file);
         byte[] bytes = new byte[(int)file.length()];
         fis.read(bytes);
         String s= new String(bytes,StandardCharsets.UTF_8);
         System.out.println(s);
         fis.close();
         fis.close();*/
        File file = new File("s.s");
        FileInputStream fis = new FileInputStream(file);
        byte[] by = new byte[(int)file.length()];
        fis.read(by);
        String line = new String(by, StandardCharsets.UTF_8);
        System.out.println(line);

        fis.close();
    }
}
